
# event for main menu
from Shell.fsm.EventDefine import event_SINGLEPLAYERGAME, event_NETWORKGAME, event_CONFIGURE, event_CREATOR
# skin
from Shell.gui.Skin import SkinGet
# gui
from Cube.gui.PreludeFinale import DropDownFrame
from direct.gui.DirectGui import DirectButton
from Cube.gui.DirectGUIPropertiesAccess import BtnTextSet, BtnCmdSet
from Cube.gui.QSizer import ResizedCallBackSet, BoxSizer, Spacer
from Cube.gui.DirectGUIPropertiesAccess import AlignText
# uiString
from Shell.data.UIString import uiString
# sys.exit
import sys

class MainMenuFrame(DropDownFrame):
    def __init__(self):
        """\
MainMenuFrame.__init__(self)
    Create a MainMenuFrame."""
        DropDownFrame.__init__(self)

        ParameterDict = SkinGet("Main menu")

        param_sizerMain = ParameterDict["main sizer"]
        param_btn = ParameterDict["btn"]
        param_btn["parent"] = self

        # single player
        param_btn["text"] = uiString["Single Player"]
        btn_SinglePlayerGame = DirectButton(**param_btn )
        # network
        param_btn["text"] = uiString["Network"]
        btn_NetworkGame = DirectButton(**param_btn )
        # Configure
        param_btn["text"] = uiString["Configure"]
        btn_Configure = DirectButton(**param_btn )
        # creator
        param_btn["text"] = uiString["Creator"]
        btn_Creator = DirectButton(**param_btn )
        # exit
        param_btn["text"] = uiString["Exit"]
        btn_Exit = DirectButton(**param_btn )

        BtnCmdSet(btn_SinglePlayerGame, messenger.send, [event_SINGLEPLAYERGAME])
        BtnCmdSet(btn_NetworkGame, messenger.send, [event_NETWORKGAME])
        BtnCmdSet(btn_Configure, messenger.send, [event_CONFIGURE])
        BtnCmdSet(btn_Creator, messenger.send, [event_CREATOR])
        BtnCmdSet(btn_Exit, sys.exit)
        # add gui object into sizer
        sizerMain = BoxSizer(BoxSizer.VERTICAL,
                             gap = param_sizerMain["gap"],
                             size = param_sizerMain["size"])
        sizerMain.Add(btn_SinglePlayerGame, 0)
        sizerMain.Add(btn_NetworkGame, 0)
        sizerMain.Add(btn_Configure, 0)
        sizerMain.Add(btn_Creator, 0)
        sizerMain.Add(Spacer(0.1), 0)
        sizerMain.Add(btn_Exit, 0)
        # alignment gui object's text
        ResizedCallBackSet(btn_SinglePlayerGame, AlignText, frame = btn_SinglePlayerGame, align = "" )
        ResizedCallBackSet(btn_NetworkGame, AlignText, frame = btn_NetworkGame, align = "" )
        ResizedCallBackSet(btn_Configure, AlignText, frame = btn_Configure, align = "" )
        ResizedCallBackSet(btn_Creator, AlignText, frame = btn_Creator, align = "" )
        ResizedCallBackSet(btn_Exit, AlignText, frame = btn_Exit, align = "" )
        # do sizer layout
        sizerMain.Layout()

        self.Prelude()
